package data;

import java.util.List;
import java.util.Map;

import org.jsoup.nodes.Document;

/**
 * @author Gavin Greene
 * @author Dan Dalton
 *
 *	A page can be created, fetched, parsed and analysed during a web crawl.
 */
public class Page {
	/**
	 * STATUS.CREATED
	 */
	private String my_url;
	public STATUS my_status;
	/**
	 * STATUS.FETCHED
	 */
	private Document my_doccument; //after a connection, jsoup gives us a doccument
	/**
	 * STATUS.PARSED
	 */
	private List<String> my_links;
	private List<String> my_words;
	/**
	 * STATUS.ANALYSED
	 */
	private Map<String, Integer> my_data;
	
	/**
	 * Time for this page to get parsed.
	 */
	private long my_parsetime;
	/**
	 * Pages take URL's and will eventually get parsed into interesting data...
	 * @param the_url to a webpage that works hopefully...
	 */
	public Page(String the_url){
		my_url = the_url;
		my_status = STATUS.CREATED;
		my_parsetime = (long)0;		
	}
	/**
	 * Run at the end of fetching a page.
	 * @param status Set to FETCHED
	 * @param doc Fetched Document
	 * @param runtime In milliseconds.
	 */
	public void setStatus(final STATUS status,final Document doc,final long runtime){
		my_doccument = doc;
		my_status = status;
		my_parsetime += runtime;
	}
	/**
	 * Run at the end of parsing a page.
	 * @param status Set to PARSED
	 * @param words Words contained by document.
	 * @param links URLs contained by document.
	 * @param runtime In milliseconds.
	 */
	public void setStatus(final STATUS status,final List<String> words,final List<String> links, final long runtime){
		my_words = words;
		my_links = links;
		my_status = status;
		my_parsetime += runtime;
		
	}
	/**
	 * Run at the end of Analysing a page.
	 * @param status Set to ANALYSED
	 * @param data Keywords and their number of occurrences.
	 * @param runtime In milliseconds.
	 */
	public void setStatus(STATUS status, final Map<String, Integer> data, final long runtime){
		my_data = data;
		my_status = status;
		my_parsetime += runtime;
	}
	/**
	 * @return my URL.
	 */
	public String getUrl(){
		return my_url;
	}
	/**
	 * @return my Document.
	 */
	public Document getDoc(){
		return my_doccument;	
	}
	/**
	 * @return A list of URLs found in this page.
	 */
	public List<String> getLinks(){
		return my_links;
	}
	/**
	 * @return A list of Words found in this page.
	 */
	public List<String> getWords(){
		return my_words;
	}
	/**
	 * @return The pairs of Keywords and their Counts.
	 */
	public Map<String, Integer> getData(){
		return my_data;
	}
	/**
	 * @return The number of URL's found on this page.
	 */
	public int getNumUrls(){
		return my_links.size();
	}
	/**
	 * @return The number of Words found on this page.
	 */
	public int getNumWords (){
		return my_words.size();
	}
	/**
	 * @return The amount of time taken to parse this page.
	 */
	public Long getParseTime(){
		return my_parsetime;
	}
	
}
